package cj.web.tb.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.tb.domain.TBRecommendation;

/**
 * 
 * @author 
 *
 */
@DAO
public interface TBRecommendationDAO{
	
	@SQL("SELECT * FROM TBRecommendation WHERE deleteFlag=1 #if(:t.userId != null){ AND userId=:t.userId } #if(:t.gameId != null){ AND gameId=:t.gameId } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<TBRecommendation> queryByUserId(@SQLParam("t") TBRecommendation tBRecommendation);
	
	@SQL("SELECT count(1) FROM TBRecommendation WHERE deleteFlag=1 #if(:t.userId != null){ AND userId=:t.userId } #if(:t.gameId != null){ AND gameId=:t.gameId } ")
    int queryByUserIdSize(@SQLParam("t") TBRecommendation tBRecommendation);
	
	@SQL("SELECT a.*,b.schoolName,b.schoolModel,b.classNum FROM TBRecommendation a JOIN TBSchoolRegistration b ON a.userId = b.userId WHERE a.deleteFlag=1 #if(:t.gameId != null){ AND a.gameId=:t.gameId } ORDER BY a.updateAt DESC LIMIT :t.start,:t.length ")
    List<TBRecommendation> query(@SQLParam("t") TBRecommendation tBRecommendation);
	
	@SQL("SELECT count(1) FROM TBRecommendation WHERE deleteFlag=1 #if(:t.gameId != null){ AND gameId=:t.gameId } ")
    int querySize(@SQLParam("t") TBRecommendation tBRecommendation);
    
    @SQL("SELECT * FROM TBRecommendation WHERE id=:1")
    TBRecommendation queryById(int id);
    
    @SQL("INSERT INTO TBRecommendation (userId,gameId,gameName,num,status,deleteFlag,createAt,createUser,updateAt,updateUser,remark) VALUES (:t.userId,:t.gameId,:t.gameName,:t.num,:t.status,1,now(),:t.createUser,now(),:t.updateUser,:t.remark)")
    void create(@SQLParam("t") TBRecommendation tBRecommendation);
	
	@SQL("UPDATE TBRecommendation SET gameId=:t.gameId,gameName=:t.gameName,status=:t.status,num=:t.num,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") TBRecommendation tBRecommendation);
	
	@SQL("UPDATE TBRecommendation SET status=:2,updateAt=now(),updateUser=:3,remark=:4 WHERE id=:1 ")
    void updateStatus(int id, int status, String updateUser, String remark);
    
    @SQL("UPDATE TBRecommendation SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}